const app = new Vue({
  el: '#app',
  components: { // 局部定义组件
    t1: {
      template: '#t1',
      data() {
        return {
          ispc: true
        }
      },
      created() {
        this.ispc = !this.platform();
        console.log('ispc=', this.ispc)
      },
      mounted() {
        const that = this
        window.addEventListener('message', msg => {
          console.log('msg=', msg)
          if (!that.ispc) {
            document.getElementById('dialog').style.display = 'none'
          }
          if (msg && typeof msg === 'object') {
            const data = msg.data || ''
            if (data && typeof data === 'object') {
              const devtoolsEnabled = data.devtoolsEnabled
              if (devtoolsEnabled) {
                return
              }
            }
            that.cb(data)
          }
        }, false)
      },
      beforeDestroy() {
        window.removeEventListener('message')
      },
      methods: {
        platform() {
          const inBrowser = typeof window !== 'undefined';
          const inWeex = typeof WXEnvironment !== 'undefined' && !!WXEnvironment.platform;
          const weexPlatform = inWeex && WXEnvironment.platform.toLowerCase();
          const UA = inBrowser && window.navigator.userAgent.toLowerCase();
          const PlatformOfAndroid = (UA && UA.indexOf('android') > 0) || (weexPlatform === 'android');
          const PlatformOfIOS = (UA && /iphone|ipad|ipod|ios/.test(UA)) || (weexPlatform === 'ios');
          const PlatformOfApp = PlatformOfIOS || PlatformOfAndroid;
          return PlatformOfApp
        },
        cb (pctype = 'unknow') {
          document.getElementById('cb').innerHTML = 'func 调用成功了 ' + pctype
        },
        btnAction() {
          // *** 注意 &frame=vue
          const href = '/login?type=1&frame=vue&a=1'
          window.open(href, null, " height=500,width=300, Left=300px,Top=20px, menubar=no,titlebar=no,scrollbar=no,toolbar=no, status=no,location=no")
        },
        ifrAction() {
          // *** 注意 &frame=vue
          document.getElementById('dialog').style.display = 'inherit'
          const href = '/login?type=2&frame=vue&a=1&b=3&c=4&d=5'
          const ifr = document.getElementById('ifr').src = href
          console.log('vue2.x -> ifr=', ifr)
        }
      }
    }
  }
})